#include <stdio.h>

int main()
{
	int t;
	scanf ("%d", &t);
	while (t--)
	{
		int n, x, y, z;
		scanf ("%d %d %d %d", &n, &x, &y, &z);
		x = 1000 * x + 100 * y + 10 * z;
		bool any = false;
		for (int a = 9; a > 0; a--)
		{
			int amount = a * 10000 + x;
			int b = n - amount % n;
			if (b == n)
				b = 0;
			if (b < 10)
			{
				b += (10 - b - 1) / n* n;
				printf ("%d %d %d\n", a, b, (amount + b) / n);
				any = true;
				break;
			}
		}
		if (!any)
			printf ("0\n");
	}
	return 0;
}